<style>
    .show{display: inherit}
    .hide{display: none}
    .layui-btn{margin-right: 10px}

.layui-table-cell {overflow-x: hidden;overflow: inherit; }
.layui-table-cell{padding:2px 4px;line-height:20px;}
th span,.layui-table-cell{white-space:normal;}
.layui-form-item .layui-inline{margin-right:0px;}
.createBillTemp{line-height:38px;}
.createBillTemp select{width:180px;height:30px;}
.fixed-bar{height:auto !important;}
.redclass{color:red;font-weight:bold;}
.layui-form-pane .layui-form-label{width:auto;}
.warning{background-color:#FF9900 !important;}
</style>
<div class="fixed-bar" style="clear:both;">
    <form class="layui-form layui-form-pane fixed-bar-form" action="{:url('',['status' => $status])}" method="get" id="hisi-table-search">
        <div class="layui-form-item">
            <div class="layui-inline">
               <label class="layui-form-label">订单号</label>
                <div class="layui-input-inline">
                    <input type="text" name="client_ordernum" lay-verify="" placeholder="输入订单号" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label ">下单日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="create_date_range" readonly="" id="create_date_range" lay-verify="" placeholder="选择创建日期" class="layui-input">
                </div>
            </div>
            <div class="layui-inline allsearch">
               <label class="layui-form-label">供应商名称</label>
                <div class="layui-input-inline">
                    {:Form::select('stall_id','' , $stallsKV, 'stall-ids', 'layui-input','lay-search=""')}
                </div>
            </div>
            <div class="layui-inline">
               <label class="layui-form-label">供应商单号</label>
                <div class="layui-input-inline">
                    <input type="text" name="stall_order" lay-verify="" placeholder="输入应商单单号" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label ">商单日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="stall_order_time" readonly="" id="stall_order_time" lay-verify="" placeholder="选择供应商日期" class="layui-input">
                </div>
            </div>
            <div class="layui-inline recheck">
                <label class="layui-form-label ">帐单所属期</label>
                <div class="layui-input-inline">
                    <input type="text" name="create_date_range" readonly="" id="create_date_range1" lay-verify="" placeholder="选择创建日期" class="layui-input">
                </div>
            </div>
            <div class="layui-inline recheck">
               <label class="layui-form-label">付款金额</label>
                <div class="layui-input-inline">
                    <input type="text" name="min_money" lay-verify="" placeholder="最小金额" style="width:45%;display:inline;" class="layui-input"> -
                    <input type="text" name="max_money" lay-verify="" placeholder="最大金额" style="width:45%;display:inline;" class="layui-input">
                </div>
            </div>
            <div class="layui-inline recheck">
               <label class="layui-form-label">付款类型</label>
                <div class="layui-input-inline">
                    {:Form::select('pay_type','', [''=> '请选择', 1=>'月结', 2=>'现金',3=>'半月结'], '', '')}
                </div>
            </div>
            
            <div class="layui-inline">
               <label class="layui-form-label">sku</label>
                <div class="layui-input-inline" style="width:120px;">
                    <input type="text" name="sku" lay-verify="" placeholder="输入sku" class="layui-input">
                </div>
            </div>
           <div class="layui-inline">
                <label class="layui-form-label">所属工厂</label>
                <div class="layui-input-inline">
                    {:Form::select('factory_id', '', $factoryKV, '', '')}
                </div>
            </div>
            <div class="layui-inline">
               <label class="layui-form-label">材料名称</label>
                <div class="layui-input-inline"  style="width:120px;">
                    <input type="text" name="name" lay-verify="" placeholder="输入材料名称" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
               <label class="layui-form-label">初审人</label>
                <div class="layui-input-inline" style="width:120px;" >
                    <input type="text" name="checkuser" lay-verify="" placeholder="初审人关键字" style="width:120px;" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
               <label class="layui-form-label">采购员</label>
                <div class="layui-input-inline" style="width:120px;" >
                    <input type="text" name="caigou_user" lay-verify="" placeholder="采购员关键字" style="width:120px;" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">单价差异</label>
                <div class="layui-input-inline" style="width:100px;">
                	{:Form::select('price_diff_logic', '>', ['gt'=>'大于', 'lt'=>'小于','eq'=>'等于'], '', '')}
                    
                </div>
                <div class="layui-input-inline" style="width:90px;">
                	<input type="text" name="price_diff" style="width:66px;display:inline-block" lay-verify="" placeholder=" 价格" class="layui-input"> 
                </div>
            </div>
            <!--<div class="layui-inline">
               <label class="layui-form-label">材料类型</label>
                <div class="layui-input-inline">
                    {:Form::select('material_type','', [''=> '请选择', 1=>'面料/里料', 2=>'辅料'], '', '')}
                </div>
            </div>-->
            <div class="layui-inline searchSubmit">
                <button type="submit" id="seacher" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
                <button type="button" class="layui-btn layui-btn-primary hisi-export topsearch">导出</button>
            </div>
        </div>
    </form>
</div>
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief" style="clear:both;">
  <ul class="layui-tab-title">
    <li class="layui-this"><a onclick="statCli(1)" href="#">等待对账（<span class="red bold stat-num-1">{:arrayGet($statData, 1, 0)}</span>条）</a></li>
    <li><a onclick="statCli(2)" href="#">对账中（<span class="red bold stat-num-2">{:arrayGet($statData, 2, 0)}</span>条）</a></li>
    <li><a onclick="statCli(3)" href="#">复核对账（<span class="red bold stat-num-3">{:arrayGet($statData, 3, 0)}</span>条）</a></li>
    <li><a onclick="statCli(4)" href="#">对帐明细</a></li>
  </ul>
    <div class="layui-tab-content">
        <table id="dataTable" lay-filter="demoEvent"></table>
    </div>
</div>      

<div id="defectiveTpl" style="display:none">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
    <div class="layui-form-item pt20 pl20 createBillTemp" style="padding-right:20px;">
    	帐单所属期：{:Form::select('billmonth',$select_month, $billmonth, '', '','lay-ignore onchange="setUrlParam(this)"')}<br />
		&nbsp; &nbsp; 付款类型：{:Form::select('pay_type','1', [ 1=>'月结', 2=>'现金', 3=>'半月结'], '', '','lay-ignore onchange="setUrlParam(this)"')}
        <div style="padding-top:20px;">
            <input type="hidden" name="order_id" value="{{ d.order_id }}">
            <input type="hidden" name="url" value="{{ d.url }}">
            <div style="text-align:center;">
              <button data-href="{:url('StallBill/makeStallBill')}?pay_type=1&billmonth={:$select_month}" 
              class="layui-btn j-page-btns layui-icon confirmSubmitCreateBill" lay-submit lay-filter="confirmSubmitCreateBill" >确认提交</button>
            </div>
        </div>
    </div>
	</form>
</div>


{include file="system@block/layui" /}

<script type="text/html" id="skuTpl">
	{{# if(d.order_time >0){ }}
    	{{ layui.util.toDateString(d.order_time*1000,'yyyy-MM-dd HH:mm:ss') }} <br>
	{{# }else{ }}
		-无订单-<br>
	{{# } }}
	{{# if(d.omc_status==1){ }}
        <a class="layui-btn layui-btn-normal layui-btn-xs copy-item" title="{{d.omc_client_ordernums}}" id="tips{{d.client_ordernum}}" data-copy="{{d.omc_client_ordernums}}" mouseleave="close({{d.client_ordernum}})" onmouseover="showDiv({{d.client_ordernum}})">合</a>
    {{# } }}
    <span class="copy-item">{{ d.client_ordernum }}</span> <br>
    <span class="copy-item">{{ d.sku }}</span></br>
</script>
<script type="text/html" id="factoryTpl">	
	{{factoryKV[d.factory_id]}}<br />
    {{d.quantity}}件  {{d.shicai_count}}件<br />
	{{# if(d.client_status == 99){ }}
		<span class="red">{{ clientStatus[d.client_status] }}</span>
	{{# }else{ }}
		{{ clientStatus[d.client_status] }}
	{{# } }}
</script>
<script type="text/html" id="materialTpl">
    {{# if(d.is_share== 1){ }}
        <a class="layui-btn layui-btn-normal layui-btn-xs layui-bg-orange">共</a>
    {{# } }}
    <span class="copy-item">{{ d.mInfo.name }}</span><br />
	{{d.mInfo.color}}
</script>
<script type="text/html" id="unit">
{{d.mInfo.unit}}
</script>
<script type="text/html" id="color">
{{d.mInfo.color}}
</script>
<script type="text/html" title="操作按钮模板" id="buttonTpl">
    <a href="{:url('stallCost/add')}?stall_feed_id={{d.id}}" class="hisi-iframe blue" hisi-data="{width: '70%', height: '70%'}" title="费用单">增加费用单</a></br>
    <a href="{:url('stallCost/stallCostDetail')}?stall_feed_id={{d.id}}" title="费用单" class="hisi-iframe blue" hisi-data="{width: '70%', height: '90%'}">查看费用单</a>
</script>
<script type="text/html" id="toolbar">
    <div class="layui-btn-group fr">
		<a data-href="{:url('status')}?val=2" class="layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon check">审核</a>&nbsp;&nbsp;
		<a  href="{:url('addStallFeed')}?mid={{ d.mid }}" title="增加采购入单" hisi-data="{width: '1200px', height: '88%'}"
		 class="hisi-iframe layui-btn layui-btn-primary layui-btn-sm layui-icon check">增加采购入单</a>&nbsp;
        <a data-href="{:url('status')}?val=1" class="layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon back">撤销</a>&nbsp;&nbsp;
		<a href="#" class="layui-btn layui-btn-primary layui-btn-sm make-bill createBillList">生成帐单</a>
		
    </div>
</script>
<script type="text/html" id="detailTpl">
    <a href="{:url('StallBillFeed/stallBillFeedDetail')}?stall_bill_id={{d.id}}" title="明细表" class="hisi-iframe blue" hisi-data="{width: '100%', height: '100%'}">打开</a>
<!--    <form class="layui-form layui-form-pane fixed-bar-form" action="{:url('StallBillFeed/stallBillFeedDetail')}?stall_bill_id={{d.id}}" method="get" id="hisi-table-search">-->
        <a href="{:url('StallBillFeed/stallBillFeedDetail')}?stall_bill_id={{d.id}}&export=1" style="cursor:pointer;border: none" class="blue hisi-export">下载</a>
<!--    <form>-->
</script>
<script type="text/html" id="stallIdTpl">
    <div class="stall-select">
        {:Form::select('stall_id','', $stallsKV, 'stall-ids-{literal}{{d.id}}{/literal}', 'layui-input stall-ids','lay-search="" lay-filter="stallIds" lay-verify="required" data-id="{literal}{{d.id}}{/literal}"')}
    </div>
</script>
<script type="text/html" title="来退料明细" id="tiaoshuDetailTpl">
	{{# if(d.tiaoshu_detail!=''){ }}
		<a href="{:url('../mp/Purchasing/materialLog')}?mid={{ d.mid }}" title="来退料明细" class="hisi-iframe" hisi-data="{width: '500px', height: '400px'}">{{ d.tiaoshu_detail }}</a>
	{{# } }}
</script>

<script type="text/javascript">
	var clientStatus = {:json_encode($clientStatus);};
	var factoryKV= {:json_encode($factoryKV);};
	var paytype = ['', "月结","现金", "半月结"];
    layui.use(['table', 'laydate', 'form', 'laytpl','tool','layer'], function() {
        var $ = layui.jquery;
        var table = layui.table;
        var laydate = layui.laydate;
        var form = layui.form;
		var laytpl=layui.laytpl;
        var layer = layui.layer;
		var initialize=0,second_initialize=0,first_init=0,changetab=0;
        laydate.render({
		    elem: '#create_date_range'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
	    	,change: function(value, date, endDate){
		    	$('#create_date_range').val(value);
            	$('#layui-laydate1').remove();//关闭面板
            }
		});
        laydate.render({
		    elem: '#create_date_range1'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
	    	,change: function(value, date, endDate){
		    	$('#create_date_range1').val(value);
            	$('#layui-laydate2').remove();//关闭面板
            }
		});
        
        laydate.render({
		    elem: '#stall_order_time'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
	    	,change: function(value, date, endDate){
		    	$('#stall_order_time').val(value);
            	$('#layui-laydate3').remove();//关闭面板
            }
		});
		window.status=0;
        window.statCli = function(status) {
			var url='{:url()}?status='+status;
			window.status=status;
			if(status==4){
				var url="{:url('StallBillFeed/stallBillFeedDetail')}?status="+status;
			}
            $("#hisi-table-search").attr('action',url);
            $("#seacher").click();  
			changetab=1;  
		}
		
        table.render({
            elem: '#dataTable'
            ,url: '{:url("", ["status" => $status])}' //数据接口
            ,page: true //开启分页
            //,skin: 'row'
            ,even: true
            ,limit: 30
            ,limits: [30,50,100,150,200,500,1000,3000]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            
            ,defaultToolbar: ['exports', 'print']
            ,cols: [[ //表头
                {type:'checkbox',field:'checkbox'}
                ,{field: 'check_time', title: '审核时间', templet: function(d){return layui.util.toDateString(d.check_time*1000,'yyyy-MM-dd HH:mm:ss')},width:86}
               ,{field: 'col1', title: '下单日期/订单号/sku', templet:'#skuTpl',width:160}
			   ,{field: 'factory', title: '分配工厂/订单数/实裁数/进度', templet:'#factoryTpl',width:120}
               ,{field: 'col2', title: '材料名称/颜色',templet:function(d){return layui.tool.formatMaterialType(d.mInfo.type, '', 2) +
			    '<span class="copy-item">' + d.mInfo.name + '</span> <br>' + d.mInfo.color+'';},width:140}
				,{field: 'stall_time', title: '供应商单日期/单号', templet: function(d){return layui.util.toDateString(d.stall_order_time*1000,'yyyy-MM-dd')+"<br>"+d.stall_order},width:96}
               ,{field:'stalls_id',title : '供应商',templet:'#stallIdTpl',width:130}
			   ,{field:'billing_caigou_kgcount',title : '开单采购公斤数/公斤价',width:90,templet:function(d){ return d.billing_caigou_kgcount+" / "+d.billing_caigou_kgprice;}}
               //,{field:'billing_caigou_kgprice',title : '开单采购公斤价',width:75}
			   ,{field: 'billing_caigou_count_feed', title: '采购数量(米)'} 
			   ,{field: 'billing_caigou_count', title: '开单采购总数（米）',width:90} 
			   ,{field: 'caichuang_shiji_dosage', title: '实际单件用量'} 
			   ,{field: 'dosage_count', title: '实际总用量'} 
			   ,{field: 'dosage_use_diff', title: '<strong>总用量差异</strong>',templet:function(d){
			   		 var classval=parseFloat(d.dosage_use_diff) != 0 ? 'have_diff' :'';return "<span class='"+classval+"'>"+d.dosage_use_diff+"</span>";}} 
			   ,{field: 'tiaoshu', title: '条数'} 
			   ,{field:'tiaoshu_detail',title : '条数明细',width:80,templet:'#tiaoshuDetailTpl'}
			   ,{field: 'customer_price', title: 'MES单价'}
               ,{field: 'caigou_unitprice', title: '采购单价',templet:function(d){
			   		 var classval=parseFloat(d.caigou_unitprice) > parseFloat(d.customer_price)? 'redclass' :'';return "<span class='"+classval+"'>"+d.caigou_unitprice+"</span>";}}
			   ,{field: 'price_diff', title: '<strong>单价差异</strong>',templet:function(d){
			   		 var classval=parseFloat(d.price_diff) != 0 ? 'have_diff' :'';return "<span class='"+classval+"'>"+d.price_diff+"</span>";}} 
			   ,{field: 'settle_unitprice', title: '结算单价',edit:'text',style:'border-bottom:2px dotted #5FB878;',templet:function(d){
			   		 var classval=parseFloat(d.settle_unitprice) > parseFloat(d.customer_price)? 'redclass' :'';return "<span class='"+classval+"'>"+d.settle_unitprice+"</span>";},width:75}  
			   ,{field: 'settle_amount', title: '结算金额'}  
               ,{field: 'billing_caigou_amount', title: '采购总金额',edit:'text',style:'border-bottom:2px dotted #5FB878;'}
               ,{field: 'admin_name', title: '采购员/录入人',templet:function(d){ return d.caigou_name!='' ? d.caigou_name+"<br>"+d.admin_name : d.admin_name;}}
			   ,{field: 'surplus_metre', title: '订单余料情况'} 
			   ,{field: 'in_stocktotal', title: '入库米数'} 
			   //,{field: 'tiaoshu', title: '退换料状态'} 
			   ,{field: 'check_name', title: '初审人'}
               ,{field: 'col3', title: '操作',templet:'#buttonTpl',width:100}
               ,{field: 'pay_month', title: '账单所属期',width:90}
			   ,{field: 'pay_type', title: '付款类型',width:130,templet:function(d){return paytype[d.pay_type];}}
               ,{field: 'stall_name', title: '供应商',width:130}
               ,{field: 'amount_money', title: '应付金额/元',width:122}
               ,{field: 'feed_money', title: '补扣金额/元',width:122}
               ,{field: 'actually_money', title: '实付金额/元',width:122}
			   ,{field: 'create_time', title: '对帐时间', templet: function(d){return layui.util.toDateString(d.create_time*1000,'yyyy-MM-dd HH:mm:ss')},width:150}
			   ,{field: 'recheck_create_user', title: '复核人',width:80}
               ,{field: 'col4', title: '明细表', templet: '#detailTpl',width:110}
			   ,{field: 'order_time', title: '下单日期',templet: function(d){return layui.util.toDateString(d.ordertime*1000,'yyyy-MM-dd HH:mm:ss')},width:140}
                ,{field: 'client_ordernum', title: '订单号',templet: function(d){return "<span class='copy-item'>"+d.sfInfo.client_ordernum+"</span>"}}
                ,{field: 'stall_name2', title: '供应商', width:130,templet: function(d){return d.stall_name}}
                ,{field: 'pic', title: '材料信息',templet:function(d){return layui.tool.formatMaterialType(d.mInfo.type, '', 2) +
			    '<span class="copy-item">' + d.mInfo.name + '</span>'},width:180}
				,{field: 'order_time', title: '供应商单日期',templet: function(d){return layui.util.toDateString(d.sfInfo.stall_order_time*1000,'yyyy-MM-dd')}, width:100}
                ,{field: 'billing_caigou_kgcount1', title: '采购公斤数',templet: function(d){return d.sfInfo.billing_caigou_kgcount}, width:110}
				,{field: 'customer_price2', title: 'MES单价',templet: function(d){return d.customer_price}}
               ,{field: 'caigou_unitprice2', title: '采购单价',templet:function(d){
			   		 var classval=parseFloat(d.caigou_unitprice) > parseFloat(d.customer_price)? 'redclass' :'';return "<span class='"+classval+"'>"+d.caigou_unitprice+"</span>";}}
			   ,{field: 'settle_unitprice2', title: '结算单价',edit:'text',templet:function(d){
			   		 var classval=parseFloat(d.settle_unitprice) > parseFloat(d.customer_price)? 'redclass' :'';return "<span class='"+classval+"'>"+d.settle_unitprice+"</span>";}}  
			   ,{field: 'settle_amount2', title: '结算金额',templet: function(d){return d.settle_amount}}  
                ,{field: 'amount', title: '采购总金额', width:110}
           ]]
            ,done: function(res, curr, count){
                 var data=res.data;
                var status=res.status;
                for (var i in data){
                    $('#stall-ids-'+data[i]['id']).val(data[i]['stall_id']);
					$(".have_diff").parent().addClass("warning");
                }
                layui.form.render();
				if(status==1){
					var need_field=[0,'checkbox','col1','factory','col2','stalls_id','stall_order','stall_time','caigou_unitprice','customer_price','tiaoshu','billing_caigou_count_feed',
					'billing_caigou_kgcount','billing_caigou_kgprice','settle_unitprice','settle_amount','billing_caigou_amount','admin_name','billing_caigou_count','tiaoshu_detail','dosage_count','dosage_use_diff'
					,'caichuang_shiji_dosage','price_diff','surplus_metre','in_stocktotal'];
					$('table tr[data-index=0] td').each(function(i){
					    console.log($(this).attr('data-field'));
					    if(need_field.indexOf($(this).attr('data-field'))==-1){
							$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
							$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
                        }
                    });
					
                    $('.make-bill').remove();
                    $('.layui-form-item .layui-inline').show();
					$('.recheck').hide();
                    $('.back').hide();
                }else if(status==2){
                    var need_field=[0,'check_time','checkbox','col1','factory','col2','stalls_id','stall_order','stall_time','caigou_unitprice','customer_price','tiaoshu','billing_caigou_count_feed',
					'billing_caigou_kgcount','billing_caigou_kgprice','settle_unitprice','settle_amount','billing_caigou_amount','admin_name','billing_caigou_count','tiaoshu_detail','dosage_count','dosage_use_diff'
					,'caichuang_shiji_dosage','price_diff','surplus_metre','in_stocktotal'];
					$('table tr[data-index=0] td').each(function(i){
					    console.log($(this).attr('data-field'));
					    if(need_field.indexOf($(this).attr('data-field'))==-1){
							$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
							$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
                        }
                    });
                    $('.check').remove();
					$('.layui-form-item .layui-inline').show();
					$(".topsearch").show();
					$('.recheck').hide();
                }else if(status==3){
					var need_field=['pay_month','create_time','pay_type','stall_name','amount_money','feed_money','actually_money','recheck_create_user','col4'];
					$('table tr[data-index=0] td').each(function(i){
					    if(need_field.indexOf($(this).attr('data-field'))==-1){
							$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
							$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
                        }
                    });
                    $('.make-bill').remove();
                    $('.check').remove();
                    $('.back').remove();
                    $('.layui-form-item .layui-inline').hide();
					$(".searchSubmit").show();
					$('.recheck').show();
					$('.allsearch').show();
					$(".topsearch").hide();
					
                }else if(status==4){
					var need_field=['stall_time','stall_order','pay_month','client_ordernum','pay_type','stall_name2','pic','billing_caigou_kgcount1','create_time',
					'amount','total_amount','customer_price2','caigou_unitprice2','settle_unitprice2','settle_amount2','admin_name'];
					$('table tr[data-index=0] td').each(function(i){
					    if(need_field.indexOf($(this).attr('data-field'))==-1){
							$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
							$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
                        }
                    });
                    /*var nums=[27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0];
                    for(var i in nums){
						trRemove(nums[i]);
                    }*/

                    $('.make-bill').remove();
                    $('.check').remove();
                    $('.back').remove();
					
                    $('.layui-form-item .layui-inline').hide();
					$(".searchSubmit").show();
					$('.recheck').show();
					$('.allsearch').show();
                    $(".hisi-export").show();
                }
				
                if (res.statData != [] && status!=4) {
                    var total=0,stat=res.statData;
                    for(var i in stat) {
                         total= total+Number(stat[i]);
                    }
                    $('.stat-num-1').text(stat[1]?stat[1]:0);
                    $('.stat-num-2').text(stat[2]?stat[2]:0);
                    $('.stat-num-3').text(stat[3]?stat[3]:0);
                }
                
                table.on('edit(demoEvent)', function(obj){
                     var value = obj.value //得到修改后的值
                    ,d = obj.data //得到所在行所有键值
                    ,field = obj.field; //得到字段
                    var id=d.id;
                    
                    // 编辑采购总金额
                    if (field == 'billing_caigou_amount') {
                        $.ajax({
                           type: "POST",
                           url: "{:url('stallFeedEdit')}",
                           data: "id="+d.id+"&billing_caigou_amount="+value,
                           dataType:"json",
                           success: function(res){
                              if (res.code == 1) {
                                 layer.msg(res.msg, {icon: 1});
                              } else {
                                 layer.msg(res.msg, {icon: 2,anim: 6});
                              }
                           }
                        });
                    }
                    if (field == 'settle_unitprice') {
                        $.ajax({
                            type: "POST",
                            url: "{:url('changeSettleUnitprice')}",
                            data: "id="+d.id+"&settle_unitprice="+value,
                            dataType:"json",
                            success: function(res){
                                if (res.code == 1) {
                                    $(obj.tr.selector+ ' td[data-field="settle_amount"]').find("div").html(res.data.settle_amount);
                                    layer.msg(res.msg, {icon: 1});
                                } else {
                                    layer.msg(res.msg, {icon: 2,anim: 6});
                                }
                            }
                        });
                    }
                });
                $('.stall-select .layui-anim-upbit').append("<a href='{:url('Stalls/add')}' hisi-data='{}' style='margin-left:5px' class='layui-btn hisi-iframe'>去新增</a>");
            }
        });

            form.on('select(stallIds)', function(data){   
                var val=data.value,id=data.elem.id;
                var elem=($('#'+id));
                $.ajax({
                   type: "POST",
                   url: "{:url('stallFeedEdit')}",
                   data: "id="+elem.attr("data-id")+"&stall_id="+elem.val(),
                   dataType:"json",
                   success: function(res){
                        if (res.code == 1) {
                            layer.msg(res.msg, {icon: 1});
                        } else {
                             layer.msg(res.msg, {icon: 2,anim: 6});
                        }
                   }
                });
            });

        window.trRemove = function(n) {
			$('table tr td:nth-child('+n+')').remove();
			$('table tr th:nth-child('+n+')').remove();
		}
		
		//设置url参数值
		window.setUrlParam=function(tabs) {
			var para_name=[$(tabs).attr('name')];
			var para_value=[$(tabs).val()];
			
			//para_name, para_value
			var oUrl = $(".confirmSubmitCreateBill").eq(1).attr("data-href").toString();
			for(var i=0;i<para_name.length;i++)
			{
				var re=eval('/('+ para_name[i]+'=)([^&]*)/gi');
				oUrl= oUrl.replace(re,para_name[i]+'='+para_value[i]);
			}
			$(".confirmSubmitCreateBill").eq(1).attr("data-href",oUrl);
		}

		
		var layerDefective = null;
		$(document).on('click','.createBillList',function(){
			if($(".layui-form-checked").size()<=0){
				layer.msg('请选择要操作的数据', {icon: 2,anim: 6});return;
			}
			var orderId = $(this).attr('data-id');
			var url = $(this).attr('data-url');
			var json = $(this).attr('data-json');
			var ordernum=$(this).attr("ordernum");
			var d = [];
			d['list'] = eval("(" + json+ ")");
			d['url'] = url;
			d['order_id'] = orderId;
			var content = laytpl($('#defectiveTpl').html()).render(d);
			layerDefective = layer.open({
				type: 1
				,shade: 0
				,offset: '100px'
				,area: ['450px','280px']
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:'生成帐单 '
				,content: content
			});
		});
		
		$(document).on('click','.confirmSubmitCreateBill',function(){
			layer.close(layerDefective);
		});

    });
</script>